package com.demo.utils;

import org.junit.Test;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * @author WuLiangHang
 */
public class FileUtils {
    HashMap<Integer, String> map = new HashMap<>();

    public void getFile(File file) {
        if (file != null) {
            File[] f = file.listFiles();
            if (f != null) {
                for (int i = 0; i < f.length; i++) {
                    getFile(f[i]);
                }
            } else {

                String fileName = file.toString().substring(43).replaceAll(".pdf", "");
                map.put(Integer.valueOf(fileName.split("-")[0]), fileName);
            }
        }
    }

    @Test
    public void getFileNames() {
        File dir = new File("D:\\Document\\学习\\开发技术\\课程\\数据结构与算法之美");
        getFile(dir);
        for (Map.Entry<Integer, String> entry :
                map.entrySet()) {
            System.out.println(entry.getValue());
        }
    }
}
